let houseId = 0
Page({
  data: {
    dialogVisible: false,
    houseList: [],
    // isLogin: true
  },
   onShow(){
    this.getHouseList()
   },
   async getHouseList(){
    const {code,data} = await wx.http.get('/room')
    if(code !== 10000) return wx.utils.toast()
    this.setData({
      houseList:data
    })
   },
  // async onLoad() {
  //   await wx.http.get('/room')
  // },

  clickDeleteBtn(ev) {
    houseId = ev.mark.id
    const { position, instance } = ev.detail

    if (position === 'right') {
      this.setData({
        dialogVisible: true,
      })

      instance.close()
    }
  },

  async dialogClose(ev) {
    // console.log(ev.detail)
    if(ev.detail === 'confirm'){
      const {code} = await wx.http.delete(`/room/${houseId}`)
      if(code !== 10000) return wx.utils.toast()
      this.getHouseList()
    }
  },

  goDetail(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + ev.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
